<?php

class ServerRpcController extends App_Controller_Action
{
	public function init()
	{
		$this->_helper->viewRenderer->setNoRender();
	}

	public function indexAction() {
			
		// Allow Services_Exceptions to report as fault responses
		//Zend_XmlRpc_Server_Fault::attachFaultException('Services_Exception');

		$server = new Zend_XmlRpc_Server();
			
		$server->setClass("Model_ServerRPC", 'YesupAcc'); // YesupAcc is namespace

		echo $server->handle();

		exit;
	}

	public function clientAction()
	{
		exit('opps');
		
		$config = Zend_Registry::get('config');
		$remote_call = $config->remote->callback->url;;
		Zend_Debug::dump($remote_call);	//exit;	
		//test1
		$client = new Zend_XmlRpc_Client($remote_call);
		/*$params = array('client_id'=> 'f8b237aa0d7fd5e9d1f041f70a7647a2',
		 'security_key'=> '5a5ab3db8fe48f61d0d635bb1669de34');
		 $response = $client->call("YesupAcc.getClientByKeyID",array($params));
		 Zend_Debug::dump($response);exit;*/

		//test2, direct login from service site
		/*$params = array('dpt_id'=> '1999',
						'dpt_account_id'=> '3',
                    	'dpt_account_login'=> 'hong');
		$response = $client->call("YesupAcc.getKeyIDByAccount",array($params));
		//Zend_Debug::dump($response);exit;

		if (!empty($response))
		{
			$url = $response['direct_login'].'?client_id='.$response['client_id'].'&security_key='.$response['security_key'];
		}
		else $url = "/";
		Zend_Debug::dump($url);
		$this->_redirect($url);*/
		
		//test3, call from emailserving, 
		
		$params = array('dpt_id'=> '3010',
                    	'dpt_account_id'=> '1',
						'email'=> 'hong@yesup.com');
		$response = $client->call("YesupAcc.getYesupIDByAccount",array($params));

		Zend_Debug::dump($response);

		exit;

	}

	public function classAction()
	{
		exit();
		$model = new Model_ServerRPC();

		// test 1
		/*$input_arr = array('client_id'=> 'f8b237aa0d7fd5e9d1f041f70a7647a2',
						           'security_key'=> '5a5ab3db8fe48f61d0d635bb1669de34');
		$info = $model->getClientByKeyID($input_arr);*/

		//Zend_Debug::dump($info);exit;
		
		
		// test 2
		/*$input_arr = array('dpt_id'=> '1500',
                       'dpt_account_login'=> 'hong');
		$info = $model->getKeyIDByAccount($input_arr);

		Zend_Debug::dump($info);*/
		
		
		// test 3
		$input_arr = array('dpt_id'=> '3010',
                       	   'dpt_account_id'=> '10',
						   'email'=> 'hong@yesup11.com'
						   );
		$info = $model->getYesupIDByAccount($input_arr);

		Zend_Debug::dump($info);
		
		
		

		exit;
	}
}